home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <cdr.h>
- #include <snd.h>
- #include "graphic.h"
- #include "event.h"
- #include "coldef.h"
-
- #define TRUE 1
- #define FALSE 0
- #define ERR (-1)
-
- #define DSP_X1 200
- #define DSP_Y1 250
- #define DSP_X2 (DSP_X1+DSP_SIZ*7+2)
- #define DSP_Y2 (DSP_Y1+15)
- #define DSP_SIZ (4*8+6)
- #define DSP_COL COL_JACK
-
- typedef struct {
- char min;
- char sec;
- char frame;
- } CDTIME;
-
- static int cd_event=ERR;
- static int type=0,strt=0,endt=0;
- static int vol=0,sts=0,no=0,acv=0,mos=ERR;
- static CDTIME st,ed;
- static CDTIME *track=NULL;
-
- static int CD_open(void)
- {
- int i;
- CDTIME disc;
-
- if ( track != NULL && acv != 0 )
- return FALSE;
-
- if ( track == NULL &&
- (track = (CDTIME *)malloc(sizeof(CDTIME)*99)) == NULL )
- return ERR;
-
- do {
- i = cdr_cdinfo(0,&type,&strt,&endt,(char *)track,(char *)&disc);
- } while ( i == CDERR7 );
-
- if ( disc.frame-- <= 0 ) {
- disc.frame = 74;
- if ( disc.sec-- <= 0 ) {
- disc.sec = 59;
- if ( disc.min-- <= 0 )
- return ERR;
- }
- }
-
- track[endt].min = disc.min;
- track[endt].sec = disc.sec;
- track[endt].frame = disc.frame;
-
- if ( i == FALSE )
- acv = TRUE;
-
- return i;
- }
- void CD_play(void)
- {
- int i;
-
- if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 )
- return;
-
- if ( sts != 0 )
- cdr_pause(0);
-
- DSP_mos(2);
- if ( CD_open() )
- return;
-
- if ( endt > 0 ) {
- for ( i=0 ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
- no = cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt]));
- }
- DSP_mos(0);
- }
- void CD_play_no(int cdn)
- {
- int i;
-
- if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 )
- return;
-
- if ( sts != 0 )
- cdr_pause(0);
-
- DSP_mos(2);
- if ( CD_open() )
- return;
-
- if ( endt > 0 ) {
- if ( (no = cdn - 1) < 0 ) no = 0;
- if ( no >= endt ) no = 0;
- for ( i=no ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
- cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt]));
- }
- DSP_mos(0);
- }
- void CD_next(void)
- {
- int i;
-
- if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 )
- return;
-
- if ( sts != 0 )
- cdr_pause(0);
- else
- no = 0;
-
- DSP_mos(2);
- if ( CD_open() )
- return;
-
- if ( endt > 0 ) {
- if ( no >= endt ) no = 0;
- for ( i=no ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
- cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt]));
- }
- DSP_mos(0);
- }
- void CD_back(void)
- {
- int i;
-
- if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 )
- return;
-
- if ( sts != 0 )
- cdr_pause(0);
- else
- no = 0;
-
- DSP_mos(2);
- if ( CD_open() )
- return;
-
- if ( endt > 0 ) {
- if ( --no <= 0 ) no = endt;
- for ( i=no-1 ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
- cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt]));
- }
- DSP_mos(0);
- }
- void CD_stop(void)
- {
- cdr_mstop(0);
- if ( track != NULL )
- free(track);
- track = NULL;
- acv = FALSE;
- }
- void CD_vol_up(void)
- {
- if ( ++vol > 127 )
- vol = 127;
- SND_elevol_set(1,vol,vol);
- }
- void CD_vol_down(void)
- {
- if ( --vol < 0 )
- vol = 0;
- SND_elevol_set(1,vol,vol);
- }
- void CD_vol_set(int n)
- {
- if ( (vol = n) < 0 ) vol = 0;
- if ( vol > 127 ) vol = 127;
- SND_elevol_set(1,vol,vol);
- }
- void CD_event(EVENT *ep)
- {
- static int tick=0;
-
- switch(ep->now) {
- case EVT_CLIP_MOS:
- EVT_clip_on(ep);
- if ( ep->no == 1 || ep->no == 2 ) {
- tick = 100;
- ep->now = EVT_REP_MOS;
- }
- case EVT_ON_MOS:
- DSP_mos(1);
- break;
-
- case EVT_SELECT_MOS:
- EVT_clip_off(ep);
- DSP_mos(0);
- cd_event = ep->no;
- break;
-
- case EVT_REP_MOS:
- if ( --tick < 0 ) {
- cd_event = ep->no;
- tick = 100;
- }
- break;
-
- case EVT_DOLACK_MOS:
- ep->now = EVT_NON;
- case EVT_MOVE_MOS:
- EVT_clip_off(ep);
- case EVT_OFF_MOS:
- DSP_mos(0);
- break;
- }
- }
-
- void CD_menu(void)
- {
- int i;
- BLOCK *save;
- static char *sw[]={ "RETN"," UP ","DOWN","STOP","BACK","PLAY","NEXT" };
-
- MOS_disp(FALSE);
- MOS_push(DSP_X1,DSP_Y1,DSP_X2,DSP_Y2);
- MOS_setpos((DSP_X1+DSP_X2)/2,(DSP_Y1+DSP_Y2)/2);
- save = DSP_push_vram(DSP_X1,DSP_Y1,DSP_X2,DSP_Y2);
- DSP_box(DSP_X1,DSP_Y1,DSP_X2,DSP_Y2,COL_LINE,DSP_COL);
-
- for ( i = 0 ; i < 7 ; i++ )
- EVT_sw(DSP_X1+i*DSP_SIZ+2,DSP_Y1+2,
- sw[i],COL_CHR,DSP_COL,600,CD_event,i);
-
- MOS_disp(TRUE);
- for ( ; ; ) {
- cd_event = ERR;
- EVT_loop(600);
- switch(cd_event) {
- case 0: goto ENDOF;
- case 1: CD_vol_up(); break;
- case 2: CD_vol_down(); break;
- case 3: CD_stop(); break;
- case 4: CD_back(); break;
- case 5: CD_play(); break;
- case 6: CD_next(); break;
- }
- }
-
- ENDOF:
- EVT_level_free(600);
- MOS_disp(FALSE);
- MOS_push(ERR,ERR,ERR,ERR);
- DSP_pop_vram(save);
- }